<template>
  <div class="auth-container">
    <div class="auth-box">
      <h2 class="auth-title">登录</h2>
      <el-form :model="loginForm" :rules="loginRules" ref="loginFormRef">
        <el-form-item prop="email">
          <el-input 
            v-model="loginForm.email" 
            placeholder="请输入邮箱"
            prefix-icon="Message"
          />
        </el-form-item>
        <el-form-item prop="password">
          <el-input 
            v-model="loginForm.password" 
            type="password" 
            placeholder="请输入密码"
            prefix-icon="Lock"
            show-password
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="submit-btn" @click="handleLogin">
            登录
          </el-button>
        </el-form-item>
      </el-form>
      <div class="auth-footer">
        <router-link to="/register" class="auth-link">
          没有账号？立即注册
        </router-link>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Message, Lock } from '@element-plus/icons-vue'

const router = useRouter()
const loginFormRef = ref(null)

const loginForm = reactive({
  email: '',
  password: ''
})

const loginRules = {
  email: [
    { required: true, message: '请输入邮箱', trigger: 'blur' },
    { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
  ]
}

const handleLogin = async () => {
  if (!loginFormRef.value) return
  await loginFormRef.value.validate((valid) => {
    if (valid) {
      // TODO: 调用登录接口
      ElMessage.success('登录成功')
      router.push('/')
    }
  })
}
</script>

<style scoped>
/* 登录页面主容器：占满视口高度，居中布局 */
.auth-container {
  min-height: calc(100vh - 200px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: #f1f5f9;
  padding-top: 60px;
}

/* 登录表单卡片：白色背景，带阴影效果 */
.auth-box {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* 登录标题：居中显示，使用深色文字 */
.auth-title {
  margin: 0 0 30px;
  text-align: center;
  font-size: 24px;
  color: #1e293b;
}

/* 登录按钮：占满容器宽度 */
.submit-btn {
  width: 100%;
  padding: 12px;
  font-size: 16px;
}

/* 底部区域：包含注册链接 */
.auth-footer {
  margin-top: 20px;
  text-align: center;
}

/* 注册链接样式：使用主题色 */
.auth-link {
  color: #0ea5e9;
  text-decoration: none;
  font-size: 14px;
}

/* 注册链接悬停效果 */
.auth-link:hover {
  color: #0284c7;
}

/* 调整输入框内部左侧padding，为图标留出空间 */
:deep(.el-input__wrapper) {
  padding-left: 11px;
}

/* 输入框前缀图标样式 */
:deep(.el-input__prefix) {
  font-size: 18px;
  color: #64748b;
}

/* 移动端适配 */
@media (max-width: 768px) {
  /* 移动端容器样式调整 */
  .auth-container {
    padding: 40px 16px;
    background: #fff;
    min-height: calc(100vh - 140px);
  }

  /* 移动端卡片样式调整 */
  .auth-box {
    padding: 20px;
    box-shadow: none;
    max-width: 100%;
  }

  /* 移动端标题样式调整 */
  .auth-title {
    font-size: 20px;
    margin-bottom: 24px;
  }

  /* 移动端按钮样式调整 */
  .submit-btn {
    padding: 10px;
    font-size: 15px;
  }

  /* 移动端表单项间距调整 */
  :deep(.el-form-item) {
    margin-bottom: 20px;
  }

  /* 移动端输入框内边距调整 */
  :deep(.el-input__wrapper) {
    padding: 0 11px;
  }
}
</style> 